<?php
class TplAccount
{
	protected static function SortMenu($a,$b)
	{
		if(isset($a['pos'],$b['pos']))
		{
			if($a['pos']>$b['pos'])
				return 1;
			if($a['pos']>$b['pos'])
				return -1;
			return 0;
		}
		elseif(isset($a['pos']))
			return -1;
		elseif(isset($b['pos']))
			return 1;
		return 0;
	}

	public static function AcMenu($handlers)
	{
		$menu=array();
		foreach($handlers as &$h)
			if(method_exists($h,'Menu') and $a=call_user_func(array($h,'Menu')))#PHP 5.3 $h::Menu()
				$menu=array_merge($menu,$a);
		usort($menu,array(__class__,'SortMenu'));
		$notact='';
		$uinfo=Eleanor::$Login->GetUserValue(array('groups','register'),false);
		if(Eleanor::$Login->IsUser() and $uinfo['groups']==array(GROUP_WAIT))
		{
			Eleanor::LoadOptions('user-profile');
			if(Eleanor::$vars['reg_type']==2)
			{
				$reg=strtotime($uinfo['register'])-time()+Eleanor::$vars['reg_act_time'];
				$notact=Eleanor::$Template->Message(Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']]['please_activate'](round($reg/3600),$GLOBALS['Eleanor']->Url->Construct(array('do'=>'activate','op'=>'new'),true,'')),'info');
			}
		}
		return Eleanor::$Template->Menu(array('title'=>end($GLOBALS['title']),'menu'=>$menu)).$notact;
	}

	public static function AcLogin($v,$handlers)
	{
		$Lst=Eleanor::LoadListTemplate('table-form');
		$captcha='';
		if($v['captcha'])
		{
			$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
			$GLOBALS['Eleanor']->Captcha->disabled=false;
			$GLOBALS['Eleanor']->Captcha->Destroy();
			$captcha=$Lst->item(array($lang['captcha'],$GLOBALS['Eleanor']->Captcha->GetCode(),'tip'=>$lang['captcha_descr'])).$Lst->item($lang['c_code'],Eleanor::Edit('check','',array('tabindex'=>3)));
		}
		$GLOBALS['title'][]=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']]['l_cabinet'];
		#Метод отвечает за внешний вид интерфейса для входа пользователя
		return self::AcMenu($handlers)
		.($v['error'] ? Eleanor::$Template->Message($v['error'],'error') : '')
			.'<form action="'.$GLOBALS['Eleanor']->Url->Construct(array('do'=>'login'),true,'').'" method="post">'
			.($v['back'] ? Eleanor::Control('back','hidden',$v['back']) : '')
			.$Lst->begin()
			->item(Eleanor::$Language['main']['login'],Eleanor::Edit('login[name]',$v['name'],array('style'=>'width:300px','tabindex'=>1)))
			->item(Eleanor::$Language['main']['pass'],Eleanor::Control('login[password]','password',$v['password'],array('style'=>'width:300px','tabindex'=>2)))
			.$captcha
			.$Lst->button(Eleanor::Button(Eleanor::$Language['main']['enter'],'submit',array('tabindex'=>5))).$Lst->end().'</form><div style="text-align:center">'.Eleanor::LoadFileTemplate(Eleanor::$root.Eleanor::$Template->default['theme'].'Static/loginza.php').'</div>';
	}

	public static function AcRegister($v,$handlers)
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$GLOBALS['title'][]=Eleanor::$Language['account']['form_reg'];
		#Метод отвечает за внешний вид интерфейса регистрации
		if(Eleanor::$vars['reg_off'])
			return self::AcMenu($handlers).Eleanor::$Template->Message($lang['reg_off'],'error');

		array_push($GLOBALS['jscripts'],'js/eleanor_acregister.js','js/eleanor_acregister-'.Language::$main.'.js');
		$Lst=Eleanor::LoadListTemplate('table-form');
		return Eleanor::JsVars(array('module'=>$GLOBALS['Eleanor']->module['name'],'min_pass'=>Eleanor::$vars['min_pass_length'],'l_min_pass'=>sprintf($lang['PASS_TOO_SHORT'],Eleanor::$vars['min_pass_length'],'%s')),true,false,'CORE.AcRegister.')
			.self::AcMenu($handlers)
			.($v['error'] ? Eleanor::$Template->Message($v['error']) : '')
			.(isset($v['external']) ? Eleanor::$Template->Message(sprintf($lang['external_reg'],empty($v['external']['nickname']) ? ($v['values']['full_name'] ? $v['values']['full_name'] : 'Anonym') : $v['external']['nickname']),'info') : '')
			.'<form method="post" onsubmit="return CORE.AcRegister.CheckReg()">'
			.$Lst->begin()
			->item(array($lang['login'],Eleanor::Edit('name',$v['values']['name'],array('id'=>'login','tabindex'=>1,'onblur'=>'CORE.AcRegister.CheckLogin()','style'=>'width:90%')).' <a href="#" onclick="CORE.AcRegister.CheckLogin();return false" title="'.$lang['chech_avail'].'"><img src="images/no_dublicate.png" alt="'.$lang['chech_avail'].'" /></a><br /><span id="login-check" style="color:green">'.$lang['enter_g_login'].'</span>','tip'=>$lang['login_descr'],'imp'=>true))
			->item($lang['op_fullname'],Eleanor::Edit('full_name',$v['values']['full_name'],array('tabindex'=>2,'style'=>'width:90%')))
			->item(array($lang['your_email'],Eleanor::Edit('email',$v['values']['email'],array('id'=>'email','tabindex'=>3,'onblur'=>'CORE.AcRegister.CheckEmail()','style'=>'width:90%')).' <a href="#" onclick="CORE.AcRegister.CheckEmail();return false" title="'.$lang['chech_avail'].'"><img src="images/no_dublicate.png" alt="'.$lang['chech_avail'].'" /></a><br /><span id="email-check" style="color:green">'.$lang['enter_g_email'].'</span>','tip'=>$lang['email_descr'],'imp'=>true))
			->item(array($lang['pass_'],Eleanor::Control('pass','password',$v['values']['p1'],array('id'=>'pass1','tabindex'=>4,'onblur'=>'CORE.AcRegister.CheckPass(1)')).'<div id="p1-check" style="color:red;display:none;"></span>','tip'=>$lang['pass_descr']))
			->item($lang['rep_pass'],Eleanor::Control('pass2','password',$v['values']['p2'],array('id'=>'pass2','tabindex'=>5,'onblur'=>'CORE.AcRegister.CheckPass(2)')).'<div id="p2-check" style="color:red;display:none;">'.$lang['pass_mm'].'</span>')
			.($GLOBALS['Eleanor']->Captcha->disabled ? '' : $Lst->item(array($lang['captcha'],$GLOBALS['Eleanor']->Captcha->GetCode(),'tip'=>$lang['captcha_descr'])).$Lst->item($lang['c_code'],Eleanor::Edit('check','',array('tabindex'=>6))))
			.$Lst->button(Eleanor::Button($lang['do_reg'],'submit',array('tabindex'=>7)))
			->end().'</form>';
	}

	public static function AcSuccessReg($handlers)
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$GLOBALS['title'][]=$lang['reg_fin'];
		return self::AcMenu($handlers).Eleanor::$Template->RedirectScreen($GLOBALS['Eleanor']->Url->Prefix(true),10)
				.Eleanor::$Template->Message($lang['success_reg'],'info');
	}

	public static function AcWaitActivate($byadmin,$handlers)
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$GLOBALS['title'][]=$lang['wait_act'];
		return self::AcMenu($handlers).Eleanor::$Template->RedirectScreen($GLOBALS['Eleanor']->Url->Prefix(true),10)
			.Eleanor::$Template->Message($byadmin ? $lang['wait_act_admin'] : sprintf($lang['wait_act_text'],round(Eleanor::$vars['reg_act_time']/3600)),'info');
	}

	public static function AcNewWaitActivate($sent,$error,$hours,$handlers)
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		if(!$sent)
			$Lst=Eleanor::LoadListTemplate('table-form');
		$GLOBALS['title'][]=$lang['activate'];
		return self::AcMenu($handlers)
			.($error ? Eleanor::$Template->Message($error,'error') : '')
			.($sent
				? Eleanor::$Template->Message($lang['wait_new_act']($hours),'info')
				: '<form method="post">'
					.$Lst->begin()
					->head($lang['activate'])
					.($GLOBALS['Eleanor']->Captcha->disabled ? '' : $Lst->item(array($lang['captcha'],$GLOBALS['Eleanor']->Captcha->GetCode(),'tip'=>$lang['captcha_descr'])).$Lst->item($lang['c_code'],Eleanor::Edit('check','',array('tabindex'=>1))))
					.$Lst->button(Eleanor::Button('OK','submit',array('tabindex'=>2)))
					->end().'</form>'
			);
	}

	public static function AcActivate($success,$handlers)
	{
		$GLOBALS['title'][]=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']]['activate'];
		if($success)
			return Eleanor::$Template->RedirectScreen($GLOBALS['Eleanor']->Url->Prefix(true),10)
				.Eleanor::$Template->Title(Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']]['success_act']);
		return self::AcMenu($handlers).Eleanor::$Template->Message(Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']]['success_ref'],'error');
	}

	public static function AcRemindPass($v,$handlers)
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$GLOBALS['title'][]=$lang['reminderpass'];
		$Lst=Eleanor::LoadListTemplate('table-form');
		$em=$v['values']['email'] and !$v['values']['name'];
		return self::AcMenu($handlers).($v['error'] ? Eleanor::$Template->Message($v['error']) : '')
			.'<form method="post">'
			.$Lst->begin()
			->head($lang['reminderpass'])
			->item(array($lang['enteryl'],Eleanor::Edit('name',$v['values']['name'],array('tabindex'=>1)).'<br /><a href="#" class="small" onclick="return ChangeLogEm()">'.$lang['fogotname'].'</a>','tr'=>array('id'=>'tr-name','style'=>$em ? 'display:none' : '')))
			->item(array($lang['enterem'],Eleanor::Edit('email',$v['values']['email'],array('tabindex'=>2)).'<br /><a href="#" class="small" onclick="return ChangeLogEm()">'.$lang['remindname'].'</a>','tr'=>array('id'=>'tr-email','style'=>$em ? '' : 'display:none'),'descr'=>$lang['notnoem']))
			.($GLOBALS['Eleanor']->Captcha->disabled ? '' : $Lst->item(array($lang['captcha'],$GLOBALS['Eleanor']->Captcha->GetCode(),'tip'=>$lang['captcha_descr'])).$Lst->item($lang['c_code'],Eleanor::Edit('check','',array('tabindex'=>3))))
			.$Lst->button(Eleanor::Button('OK','submit',array('tabindex'=>4)))
			->end()
			.'</form><script type="text/javascript">//<![CDATA[
function ChangeLogEm()
{
	$("#tr-email,#tr-name").toggle();
	return false;
}//]]></script>';
	}

	public static function AcWaitRemindPass($handlers)
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$GLOBALS['title'][]=$lang['wait_pass1'];
		return self::AcMenu($handlers)
			.Eleanor::$Template->RedirectScreen($GLOBALS['Eleanor']->Url->Prefix(true),10)
			.Eleanor::$Template->Message($lang['wait_pass1_text'],'info');
	}

	public static function AcRemindNewPass($handlers,$values,$error='')
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$values['name']=htmlspecialchars($values['name'],ELENT,CHARSET);
		$lang['new_pass']=sprintf($lang['new_pass'],$values['name']);
		$GLOBALS['title'][]=$lang['new_pass'];
		$Lst=Eleanor::LoadListTemplate('table-form');
		return self::AcMenu($handlers).($error ? Eleanor::$Template->Message($error) : '')
			.'<form method="post" onsubmit="if($(\'#p1\').val()!=$(\'#p2\').val()){alert(\''.$lang['pass_mm'].'\') return false;}">'
			.$Lst->begin()
			->head($lang['new_pass'])
			->item($lang['ent_newp'],Eleanor::Control('p1','password',$values['_p1'],array('tabindex'=>1)))
			->item($lang['rep_newp'],Eleanor::Control('p2','password',$values['_p2'],array('tabindex'=>2)))
			.($GLOBALS['Eleanor']->Captcha->disabled ? '' : $Lst->item(array($lang['captcha'],$GLOBALS['Eleanor']->Captcha->GetCode(),'tip'=>$lang['captcha_descr'])).$Lst->item($lang['c_code'],Eleanor::Edit('check','',array('tabindex'=>3))))
			.$Lst->button(Eleanor::Button('OK','submit',array('tabindex'=>4)))
			->end()
			.'</form>';
	}

	public static function AcRemindPassSent($passsent,$values,$handlers)
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$GLOBALS['title'][]=$lang['wait_pass1'];
		return self::AcMenu($handlers)
			.Eleanor::$Template->RedirectScreen($GLOBALS['Eleanor']->Url->Prefix(true),10)
			.Eleanor::$Template->Message($passsent ? $lang['new_pass_sent'] : $lang['pass_changed'],'info');
	}

	public static function AcMain($handlers)
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$GLOBALS['title'][]=$lang['l_cabinet'];
		return self::AcMenu($handlers);
	}

	public static function AcNewPass($success,$error,$values,$handlers)
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$GLOBALS['title'][]=$lang['changing_pass'];
		$Lst=Eleanor::LoadListTemplate('table-form');
		return self::AcMenu($handlers)
			.($error ? Eleanor::$Template->Message($error,'error') : '')
			.($success ? Eleanor::$Template->Message($lang['pass_changed'],'info') : '')
			.$Lst->form(array('onsubmit'=>'if($(\'[name=p1]\',this).val()!=$(\'[name=p2]\',this).val()){alert(\''.$lang['pass_mm'].'\');return false;}'))
			->begin()
			->head($lang['your_curr_pass'])
			->item($lang['en_ycp'],Eleanor::Control('old','password',$values['_old'],array('tabindex'=>1)))
			->head($lang['new_pass_me'])
			->item($lang['ent_newp'],Eleanor::Control('p1','password',$values['_p1'],array('tabindex'=>2)))
			->item($lang['rep_newp'],Eleanor::Control('p2','password',$values['_p2'],array('tabindex'=>3)))
			->button(Eleanor::Button('OK','submit',array('tabindex'=>4)))
			->end()
			->endform();
	}

	public static function AcEmailChange($values,$error,$handlers)
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$GLOBALS['title'][]=$lang['changing_email'];
		$Lst=Eleanor::LoadListTemplate('table-form');
		return self::AcMenu($handlers)
			.($error ? Eleanor::$Template->Message($error,'error') : '')
			.$Lst->form()
			->begin()
			->head($lang['changing_email'])
			->item($lang['curr_email'],($em=Eleanor::$Login->GetUserValue('email')) ? $em : '<i>'.Eleanor::$Language['main']['no'].'</i>')
			->item($lang['new_email'],Eleanor::Edit('email',$values['email'],array('tabindex'=>1)))
			.($GLOBALS['Eleanor']->Captcha->disabled ? '' : $Lst->item(array($lang['captcha'],$GLOBALS['Eleanor']->Captcha->GetCode(),'tip'=>$lang['captcha_descr'])).$Lst->item($lang['c_code'],Eleanor::Edit('check','',array('tabindex'=>2))))
			.$Lst->button(Eleanor::Button($lang['continue'],'submit',array('tabindex'=>3)))
			->end()
			->endform();
	}

	public static function AcWaitEmailChange($step,$handlers)
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$GLOBALS['title'][]=$lang['changing_email'];
		return self::AcMenu($handlers).Eleanor::$Template->Message($lang['wait_change'.$step],'info');
	}

	public static function AcOptions($handlers,$error,$values,$extra,$controls,$avatar)
	{
		list($awidth,$aheight)=explode(' ',Eleanor::$vars['avatar_size']);
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$GLOBALS['title'][]=$lang['sett_profile'];
		$GLOBALS['Eleanor']->Controls->arrname=array('avatar');
		$Lst=Eleanor::LoadListTemplate('table-form');
		$avataritem=$Lst->head($lang['avatar'])
			.$Lst->item(
				$lang['alocation'],
				Eleanor::Select(
					'_atype',
					Eleanor::Option($lang['agallery'],'gallery',!$values['_aupload'])
					.Eleanor::Option($lang['apersonal'],'upload',$values['_aupload']),
					array('id'=>'_atype')
				)
			)
			.$Lst->item(
				$lang['amanage'],
				Eleanor::Control('avatar_location','hidden',$avatar['value'],array('id'=>'avatar-input'))
				.'<div id="avatar-local">
					<div id="avatar-select" style="display:none"></div>
					<div id="avatar-view">
						<a class="uploadimagebtn" href="#" onclick="return GetAvatarGalleries()" style="text-decoration:none">'.$lang['gallery_select'].'</a><div class="clr"></div>
						<span id="avatar-no" style="width:'.($awidth ? $awidth : '180').'px;height:'.($aheight ? $aheight : '145').'px;text-decoration:none;max-height:100%;max-width:100%;" class="screenblock">
							<b>'.$lang['noavatar'].'</b><br />
							<span>'.sprintf('<b>%s</b> <small>x</small> <b>%s</b> <small>px</small>',$awidth ? $awidth : '&infin;',$aheight ? $aheight : '&infin;').'</span>
						</span>
						<img id="avatar-image" style="border:1px solid #c9c7c3;max-width:'.($awidth>0 ? $awidth.'px' : '100%').';max-height:'.($aheight>0 ? $aheight.'px' : '100%').'" src="images/spacer.png" /><div class="clr"></div>
						<a id="avatar-delete" class="uploadimagebtn" href="#" onclick="return DeleteLocalAvatar()" style="text-decoration:none">'.Eleanor::$Language['main']['delete'].'</a>
					</div>
				</div>
				<div id="avatar-upload">'.$GLOBALS['Eleanor']->Controls->DisplayControl($avatar).'</div>
				<script type="text/javascript">//<![CDATA[
				$(function(){
					$("#_atype").change(function(){
						if($(this).val()=="upload")
						{
							$("#avatar-view,#avatar-select").hide();
							$("#avatar-upload").show();
						}
						else
						{
							$("#avatar-upload").hide();
							$("#avatar-view").show();
						}
					}).change();'
					.($avatar['value'] ? '$("#avatar-image").attr("src","'.$avatar['value'].'");$("#avatar-delete").show();$("#avatar-no").hide();' : '$("#avatar-image,#avatar-delete").hide();')
					.'
				});
				function GetAvatarGalleries()
				{
					var g;
					if(g=$("#avatar-select").data("gallery"))
					{
						$("#avatar-view").hide();
						$("#avatar-select").html(g).show();
					}
					else
						CORE.Ajax(
							{
								module:"'.$GLOBALS['Eleanor']->module['name'].'",
								language:CORE.language,
								"do":"settings",
								event:"agalleries"
							},
							function(r)
							{
								$("#avatar-view").hide();
								$("#avatar-select").data("gallery",r).html(r).show();
							}
						);
					return false;
				}
				function CancelAvatar()
				{
					$("#avatar-select").hide();
					$("#avatar-view").show();
					return false;
				}
				function ShowGalleryContent(gal)
				{
					var g;
					if(g=$("#avatar-select").data("gal-"+gal))
						$("#avatar-select").html(g);
					else
						CORE.Ajax(
							{
								module:"'.$GLOBALS['Eleanor']->module['name'].'",
								language:CORE.language,
								"do":"settings",
								event:"avatars",
								gallery:gal
							},
							function(r)
							{
								$("#avatar-select").data("gal-"+gal,r).html(r);
							}
						);
					return false;
				}
				function ApplyLocalAvatar(f)
				{
					$("#avatar-input").val(f);
					$("#avatar-image").attr("src",f).add("#avatar-delete,#avatar-view").show();
					$("#avatar-no,#avatar-select").hide();
					return false;
				}
				function DeleteLocalAvatar()
				{
					$("#avatar-input").val("");
					$("#avatar-image,#avatar-delete").hide();
					$("#avatar-no").show();
					return false;
				}//]]></script>');
		$GLOBALS['Eleanor']->Controls->arrname=array('co');
		$cs=array();

		$items=$head='';
		$a=$GLOBALS['Eleanor']->Controls->DisplayControls($controls,$extra);
		$n=0;
		foreach($controls as $k=>&$v)
		{
			if(is_array($v))
				$items.=$Lst->item(array($v['title'],$a[$k],'tip'=>$v['descr']));
			else
			{
				if($head)
				{
					$cs[$n][0]=$head;
					$cs[$n++][1]=$Lst->begin().$items.($n==1 ? '' : $avataritem).$Lst->end();
				}
				$head=$v;
				$items='';
			}
		}
		$cs[$n][0]=$head;
		$cs[$n][1]=($cs ? '' : $avataritem).$Lst->begin().$items.$Lst->end();

		$back=isset($_GET['noback']) ? '' : Eleanor::Control('back','hidden',isset($_POST['back']) ? (string)$_POST['back'] : getenv('HTTP_REFERER'));
		return self::AcMenu($handlers).($error ? Eleanor::$Template->Message($error,'error') : '').$Lst->form()
			->tabs(
				array($cs[0][0],$cs[0][1]),
				array($cs[1][0],$cs[1][1]),
				array($cs[2][0],$cs[2][1])
			)
			->submitline($back.Eleanor::Button())
			->endform();
	}

	public static function AcUserInfo($user,$groups,$handlers)
	{
		$GLOBALS['title'][]=$user['full_name'];
		$Lst=Eleanor::LoadListTemplate('table-form');
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$ogr=$mgr='';
		foreach($groups as &$v)
			if($v['main'])
				$mgr.='<a href="'.$v['_href'].'">'.$v['html_pref'].$v['title_l'].$v['html_end'].'</a>';
			else
				$ogr.='<a href="'.$v['_href'].'">'.$v['html_pref'].$v['title_l'].$v['html_end'].'</a>, ';
		$cs=array();
		$controls=array(
			array(
				$lang['op_personal'],
				'gender'=>array(
					'title'=>$lang['gender'],
					'type'=>'select',
					'options'=>array(
						'options'=>array(-1=>$lang['nogender'],$lang['female'],$lang['male']),
					),
				),
				'bio'=>array(
					'title'=>$lang['bio'],
					'type'=>'text',
				),
				'interests'=>array(
					'title'=>$lang['interests'],
					'type'=>'text',
				),
				'location'=>array(
					'title'=>$lang['location'],
					'type'=>'edit',
				),
				'site'=>array(
					'title'=>$lang['site'],
					'type'=>'edit',
					'result'=>array(__class__,'Site'),
				),
				'signature'=>array(
					'title'=>$lang['signature'],
					'type'=>'editor',
				),
			),
			array(
				$lang['connect'],
				'jabber'=>array(
					'title'=>'Jabber',
					'type'=>'edit',
				),
				'skype'=>array(
					'title'=>'Skype',
					'type'=>'edit',
					'result'=>array(__class__,'Skype'),
				),
				'icq'=>array(
					'title'=>'ICQ',
					'type'=>'edit',
					'result'=>array(__class__,'ICQ'),
				),
				'vkontakte'=>array(
					'title'=>$lang['vkontakte'],
					'type'=>'edit',
					'result'=>array(__class__,'VK'),
				),
				'twitter'=>array(
					'title'=>'Twitter',
					'type'=>'edit',
					'result'=>array(__class__,'TW'),
				),
			),
			array(
				$lang['op_site'],
				'language'=>Eleanor::$vars['multilang'] ? array(
					'title'=>$lang['op_lang'],
					'type'=>'select',
				) : false,
				'theme'=>array(
					'title'=>$lang['op_theme'],
					'type'=>'select',
					'options'=>array(
						'callback'=>array(__class__,'GetThemes'),
					),
				),
				'timezone'=>array(
					'title'=>$lang['op_timezone'],
					'type'=>'select',
				),
			),
		);
		foreach($controls as $k=>&$v)
		{
			$cs[$k][0]=$v[0];
			$cs[$k][1]=$Lst->begin();
			$a=array_slice($v,1);
			foreach($a as $ka=>&$va)
				if(isset($user[$ka]) and is_array($va))
					$va['value']=$user[$ka];
				else
					unset($a[$ka]);
			$a=$GLOBALS['Eleanor']->Controls->DisplayResults($a);
			foreach($a as $k_=>&$v_)
				$cs[$k][1].=$Lst->item($v[$k_]['title'],$v_ ? $v_ : '<i>'.(in_array($k_,array('timezone','theme','language')) ? $lang['by_default'] : Eleanor::$Language['main']['no']).'</i>');
			$cs[$k][1].=$Lst->end();
		}
		$user['name']=htmlspecialchars($user['name'],ELENT,CHARSET);
		if($user['avatar_location'])
		{
			switch($user['avatar_type'])
			{
				case 'upload':
					$a=Eleanor::$uploads.'/avatars/';
				break;
				case 'local':
					$a='images/avatars/';
				break;
				default:
					$a='';
			}
			list($w,$h)=explode(' ',Eleanor::$vars['avatar_size']);
			$avatar='<img src="'.$a.$user['avatar_location'].'" style="'.($w ? 'max-width:'.$w.'px;' : '').($h ? 'max-height:'.$h.'px;' : '').'" alt="'.$user['name'].'" title="'.$user['name'].'" />';
		}
		else
			$avatar='<img src="'.Eleanor::GetImage(Eleanor::$vars['noavatar']).'" alt="'.$user['name'].'" title="'.$user['name'].'" />';
		return self::AcMenu($handlers)
			.$Lst->begin()
			.'<tr><td rowspan="6" style="padding:5px;width:10%">'.$avatar.'</td><td class="label">'.$lang['nickname'].'</td><td>'.htmlspecialchars($user['name'],ELENT,CHARSET).'</td></tr>'
			.($user['name']==$user['full_name'] ? '' : $Lst->item($lang['op_fullname'],$user['full_name']))
			.$Lst->item($lang['registered'],$user['register'])
			->item($lang['last_visit'],$user['last_visit'])
			.($mgr ? $Lst->item($lang['maingroup'],$mgr) : '')
			.($ogr ? $Lst->item($lang['othgroups'],rtrim($ogr,' ,')) : '')
			.$Lst->end()
			->tabs(
				array($cs[0][0],$cs[0][1]),
				array($cs[1][0],$cs[1][1]),
				array($cs[2][0],$cs[2][1])
			);
	}

	public static function AcGroups($groups)
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$GLOBALS['title'][]=$lang['groups'];
		$c=Eleanor::$Template->Menu(array(
			'title'=>end($GLOBALS['title']),
			'menu'=>array(array(
				$GLOBALS['Eleanor']->Url->Construct(array('module'=>$GLOBALS['Eleanor']->module['sections']['account']),false),
				$lang['l_cabinet']
			))
		));
		$Lst=Eleanor::LoadListTemplate('table-list',2)
			->begin($lang['group'],$lang['descr']);
		foreach($groups as &$v)
			$Lst->item(array($v['html_pref'].$v['title_l'].$v['html_end'],'traddon'=>array('id'=>'group-'.$v['id'])),$v['descr_l']);
		return$c.$Lst->end();
	}

	public static function VK($a)
	{
		if($a['value'])
		{
			Eleanor::LoadOptions('editor');
			return'<a href="'.(Eleanor::$vars['antidirectlink'] ? 'go.php?' : '').'http://vkontakte.ru/'.$a['value'].'" target="_blank">'.$a['value'].'</a>';
		}
		return'';
	}

	public static function TW($a)
	{
		if($a['value'])
		{
			Eleanor::LoadOptions('editor');
			return'<a href="'.(Eleanor::$vars['antidirectlink'] ? 'go.php?' : '').'http://twitter.com/'.$a['value'].'" target="_blank">'.$a['value'].'</a>';
		}
		return'';
	}

	public static function ICQ($a)
	{
		if($a['value'])
		{
			$f=number_format($a['value'],0,3,'-');
			return'<img src="http://status.icq.com/online.gif?icq='.$a['value'].'&amp;img=5" alt="'.$f.'" title="'.$f.'" /> '.$f;
		}
		return'';
	}

	public static function Skype($a)
	{
		if($a['value'])
		{
			$a['value']=htmlspecialchars($a['value'],ELENT,CHARSET,false);
			return'<a href="skype:'.$a['value'].'">'.$a['value'].'</a>';
		}
		return'';
	}

	public static function Site($a)
	{
		if($a['value'])
		{
			Eleanor::LoadOptions('editor');
			return'<a href="'.(Eleanor::$vars['antidirectlink'] ? 'go.php?' : '').(strpos($a['value'],'://')<7 ? 'http://' : '').$a['value'].'" target="_blank">'.$a['value'].'</a>';
		}
		return'';
	}

	public static function GetThemes()
	{
		$themes=array(''=>Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']]['by_default']);
		if(Eleanor::$vars['templates'] and is_array(Eleanor::$vars['templates']))
			foreach(Eleanor::$vars['templates'] as &$v)
			{
				$f=Eleanor::$root.'templates/'.$v.'.php';
				if(!file_exists($f))
					continue;
				$a=include$f;
				$name=is_array($a) && isset($a['name']) ? $a['name'] : $v;
				$themes[$v]=$name;
			}
		return$themes;
	}

	#Loginza
	public static function Loginza($items,$event,$handlers)
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$GLOBALS['title'][]=$lang['externals'];
		$s=$c='';
		switch($event[0])
		{
			case'add':
				$c.=Eleanor::$Template->Message(sprintf($lang['aexternal'],'<a href="'.$event['loginza']['identity'].'" target="_blank">'.(isset($lang[$event['loginza']['provider']]) ? $lang[$event['loginza']['provider']] : $event['loginza']['provider']).'</a>'),'info');
			break;
			case'error':
				$c.=Eleanor::$Template->Message($event['loginza'] ? $event['loginza']['error_message'] : 'Error...','error');
		}
		foreach($items as &$v)
			$s.='<span><a href="'.$v['identity'].'" target="_blank" style="font-size:2em">'.(isset($lang[$v['provider']]) ? $lang[$v['provider']] : $v['provider']).'</a><a href="#" data-provider="'.$v['provider'].'" data-uid="'.$v['provider_uid'].'" title="'.Eleanor::$Language['main']['delete'].'">X</a> </span>';
		return self::AcMenu($handlers).$c
			.'<script type="text/javascript">//<![CDATA[
$(function(){
	$("#externals").on("click","a[href=#]",function(){
		var o=$(this);
		CORE.Ajax(
			{
				module:"'.$GLOBALS['Eleanor']->module['name'].'",
				"do":"loginza",
				provider:o.data("provider"),
				pid:o.data("uid")
			},
			function()
			{
				o.closest("span").remove();
			}
		);
		return false;
	})
})//]]></script><script type="text/javascript" src="http://loginza.ru/js/widget.js"></script><div style="text-align:center;">
<img src="http://loginza.ru/img/providers/facebook.png" title="Yandex" />
<img src="http://loginza.ru/img/providers/yandex.png" title="Yandex" />
<img src="http://loginza.ru/img/providers/google.png" title="Google Accounts" />
<img src="http://loginza.ru/img/providers/vkontakte.png" title="VK" />
<img src="http://loginza.ru/img/providers/mailru.png" title="Mail.ru" />
<img src="http://loginza.ru/img/providers/twitter.png" title="Twitter" />
<img src="http://loginza.ru/img/providers/loginza.png" title="Loginza" />
<img src="http://loginza.ru/img/providers/myopenid.png" title="MyOpenID" />
<img src="http://loginza.ru/img/providers/openid.png" title="OpenID" />
<img src="http://loginza.ru/img/providers/webmoney.png" title="WebMoney" /></a><br />'.($s ? '<div id="externals">'.rtrim($s,', ').'</div><br />' : '').'<a href="https://loginza.ru/api/widget?token_url='.urlencode(PROTOCOL.Eleanor::$punycode.Eleanor::$site_path.$GLOBALS['Eleanor']->Url->Construct(array('do'=>'loginza'),true,'')).'" class="loginza link-button" style="width:150px"><b>'.$lang['add'].'</b></a></div>';
	}

	public static function LoginzaError($loginza,$handlers)
	{
		return self::AcMenu($handlers)
			.Eleanor::$Template->Message($loginza ? $loginza['error_message'] : 'Error...','error');
	}

	public static function AcUsersOnline($items,$groups,$pp,$page,$cnt)
	{
		$lang=Eleanor::$Language[$GLOBALS['Eleanor']->mconfig['n']];
		$isa=Eleanor::$Permissions->IsAdmin();
		$Lst=Eleanor::LoadListTemplate('table-list',$isa ? 5 : 4);
		$c=$Lst->begin(
			array($lang['who'],'colspan'=>2),
			$isa ? 'IP' : false,
			array($lang['activity'],120),
			$lang['pl']
		);

		if($items)
		{
			$bicons=array(
				'opera'=>array(Eleanor::GetImage('browsers/opera.png'),'Opera'),
				'firefox'=>array(Eleanor::GetImage('browsers/firefox.png'),'Mozilla Firefox'),
				'chrome'=>array(Eleanor::GetImage('browsers/chrome.png'),'Google Chrome'),
				'safari'=>array(Eleanor::GetImage('browsers/safari.png'),'Apple Safari'),
				'msie'=>array(Eleanor::GetImage('browsers/ie.png'),'Microsoft Internet Explore'),
			);
			$t=time();

			foreach($items as &$v)
			{
				$icon=$iconh=false;
				foreach($bicons as $br=>$brv)
					if(stripos($v['browser'],$br)!==false)
					{
						$icon=$brv[0];
						$iconh=$brv[1];
						break;
					}

				switch($v['type'])
				{
					case'bot':
						$name=htmlspecialchars($v['botname'],ELENT,CHARSET);
					break;
					case'user':
						if($v['name'] and $v['user_id'])
						{
							$name='<a href="'.Eleanor::$Login->UserLink($v['name'],$v['user_id']).'"'
								.(isset($v['_group'],$groups[$v['_group']]) ? ' title="'.$groups[$v['_group']]['title_l'].'">'.$groups[$v['_group']]['html_pref'].htmlspecialchars($v['name'],ELENT,CHARSET).$groups[$v['_group']]['html_end'] : '>'.htmlspecialchars($v['name'],ELENT,CHARSET))
								.'</a>'.($v['name']==$v['full_name'] ? '' : '<br /><i>'.$v['full_name'].'</i>');
							break;
						}
					default:
						$name='<i>'.Eleanor::$Language['main']['guest'].'</i>';
				}
				$v['location']=htmlspecialchars($v['location'],ELENT,CHARSET,false);
				$ip=$v['ip_guest'] ? $v['ip_guest'] : $v['ip_user'];
				$loc='<a href="'.$v['location'].'" target="_blank">'.Strings::CutStr($v['location'],100).'</a>';
				$c.=$Lst->item(
					$icon ? array('<img title="'.$iconh.'" src="'.$icon.'" />','style'=>'width:1px') : false,
					$icon ? $name : array($name,'colspan'=>2),
					$isa ? array($ip,'center','href'=>'http://eleanor-cms.ru/whois/'.$ip,'hrefaddon'=>array('target'=>'_blank')) : false,
					array(call_user_func(Eleanor::$Language['main']['minutes_ago'],floor(($t-strtotime($v['enter']))/60)),'center'),
					$loc
				);
			}
		}
		else
			$c.=$Lst->empty($lang['snf']);
		$c.=$Lst->end();
		return Eleanor::$Template->Menu(array(
			'title'=>end($GLOBALS['title']),
		)).$c.Eleanor::$Template->Pages($cnt,$pp,$page);
	}
}